function TreePath() {
    this.path = [];
    this.res = [];
}

TreePath.prototype.allPath = function(root) {
    this.dfs(root);
    return this.res;
}

TreePath.prototype.dfs = function(node) {
    if (!node) return;

    // 递的时候：将当前节点值加入到路径
    this.path.push(node.val);

    if (!node.left && !node.right) {
        this.res.push([...this.path]);
    }

    this.dfs(node.left);
    this.dfs(node.right);

    // 回溯
    // 归的时候：将当前节点从当前路径中删除
    this.path.pop();
}